package com.bscscan.dextools;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.neovisionaries.ws.client.WebSocket;
import com.neovisionaries.ws.client.WebSocketAdapter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @description:
 * @author: jintengzhou
 * @date: 2021-07-21 17:06
 */
@Slf4j
@Component
public class DexToolsWebSocketAdapter extends WebSocketAdapter {

    @Override
    public void onTextMessage(WebSocket websocket, String message) {
        final JSONObject jsonObject = JSON.parseObject(message);
        final JSONObject pair = jsonObject.getJSONObject("result").getJSONObject("data").getJSONObject("pair");
        final DexToolsInfo dexToolsInfo = JSON.parseObject(JSON.toJSONString(pair), DexToolsInfo.class);
        log.debug("接收到消息 : {}", message);
        log.info("该token的 devtools url  : https://www.dextools.io/app/pancakeswap/pair-explorer/{}", dexToolsInfo.getId());
    }

}